package trans.action;

import trans.action.support.PageMode;
import trans.model.Sa;
import trans.model.SaComment;
import trans.service.SaCommentDAO;
import trans.support.BasicSupport;
import trans.support.Constants;
import trans.utils.HibernateUtil;

import com.opensymphony.xwork2.Preparable;

public class SaCommentMgrAction extends BasicSupport implements Preparable{

	private static final long serialVersionUID = 1L;

	String saType;
	@Override
	public void prepare() throws Exception {
		initManuShow();
		
	}
	
	SaComment saComment;
	public String addComment() throws Exception{
		saComment.setCreateBy_id(currentUser().getId());
		SaCommentDAO.addComment(saComment,currentUser().getIsCustomer());
		//need reset page data
		
		saComment.setComment("");
		addActionMessage(getText("message.sacomment.create.success"));
		return search();
	}
	
	Integer saId;
	public String search() throws Exception{
		PageMode pm = getPageMode(request);
		pm.addParam(SaComment.PROP_SA_ID, saId);
		SaCommentDAO.fillCommentPage(pm);
		initPager(pm);
		
		if(currentUser().getIsCustomer()){
			Sa sa = 
				(Sa) HibernateUtil.get(Sa.class,saId);
			if(sa.getFlagRead() == Constants.STATUS_SA_HANDED){
				sa.setFlagRead(Constants.STATUS_SA_NONE);
				HibernateUtil.saveOrUpdate(sa);
			}
		}
		return "saComments";
	}

	public Integer getSaId() {
		return saId;
	}


	public void setSaId(Integer saId) {
		this.saId = saId;
	}

	public SaComment getSaComment() {
		return saComment;
	}

	public void setSaComment(SaComment saComment) {
		this.saComment = saComment;
	}

	public String getSaType() {
		return saType;
	}

	public void setSaType(String saType) {
		this.saType = saType;
	}
}
